package com.example.esaclient;

import java.util.HashMap;

public class EsaPost {

	public String message,time,socialNetwork,picture,n_likes,n_comments;
	public HashMap<String,Object> feed;
	
	public EsaPost(){
		message=time=socialNetwork=picture=n_likes=n_comments="";
	}
	
	
	public EsaPost(String esaMsg){
		String[] s;
		s=esaMsg.split("\\+\\-\\+");
		feed=new HashMap<String, Object>();
		if(s.length>=6){
		 message=s[0];
		 time=s[1];
		 socialNetwork=s[2];
		 picture=s[3];
		 n_likes=s[4];
		 n_comments=s[5];
		
		
		feed.put("message", message);
		feed.put("time", time);
		feed.put("socialNetwork","Via "+ socialNetwork);
		
	/*	if (!picture.equals("")){
			try {				 
				
				URL url = new URL(picture);
				HttpURLConnection connection  = (HttpURLConnection) url.openConnection();
				InputStream is = connection.getInputStream();
				Bitmap img = BitmapFactory.decodeStream(is, null, null);
				
				  feed.put("picture", img);
				} catch (MalformedURLException e) {
				  e.printStackTrace();
				  feed.put("picture", "");
				} catch (IOException e) {
				  e.printStackTrace();
				  feed.put("picture", "");
				}
		
		}else
			feed.put("picture", picture);*/
		
		if(socialNetwork.equals("Facebook"))
			feed.put("picture", R.drawable.fb_icon);
		else
			if(socialNetwork.equals("Twitter"))
				feed.put("picture", R.drawable.tw_icon);
			else
				feed.put("picture", R.drawable.gp_icon);
		
		feed.put("n_likes", n_likes+" Likes");
		feed.put("n_comments", n_comments+" Comments");
		}
		else{
		message="There are no posts.";
		feed.put("message", message);
		feed.put("time", "");
		feed.put("socialNetwork","");
		feed.put("picture", "");
		feed.put("n_likes","");
		feed.put("n_comments","");
		}
		
	}
	
	
}
